package com.lzj.server.listener;

import com.lzj.server.config.RabbitMQConfig;
import com.lzj.server.entity.dto.mq.VideoProcessDTO;
import com.lzj.server.common.service.DashScopeEmbeddingService; // 注入您已有的服务
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@RequiredArgsConstructor
public class VideoProcessingListener {

    private final DashScopeEmbeddingService embeddingService;
    // 可能还需要 VideoVectorModelService
    // private final VideoVectorModelService vectorModelService;

    @RabbitListener(queues = RabbitMQConfig.QUEUE_VIDEO_EMBEDDING_GENERATION)
    public void onVideoUploaded(VideoProcessDTO event) {
        log.info("收到视频处理任务，开始生成 Embedding: {}", event);
        try {
            // 在这里调用您已经写好的 Embedding 服务
            // String vector = embeddingService.generateVector(event.videoTitle());
            // vectorModelService.saveVector(event.videoId(), vector);
            log.info("视频 {} 的 Embedding 生成完毕。", event.videoId());
        } catch (Exception e) {
            log.error("Embedding 生成失败，消息将根据配置重试或进入死信队列: {}", event, e);
            // 抛出异常，触发 Spring AMQP 的重试机制
            throw new RuntimeException("Embedding generation failed", e);
        }
    }
}